fix(compose): reconcile up -d by service config hash#63
Merged
Conversation
Previously ObservedContainer.state always defaulted to .running because up() never populated it from the real container state, so reconcileDecision's .keep branch fired purely on config-hash equality. A .keep action skipped the start loop and unconditionally emitted .containerRunning, so a stopped-but-matching container was left stopped while mocker reported it as Running. - Populate ObservedContainer.state from the real container state in up(). - Split ReconcileAction.Kind with a new .start case: hash matches but the container isn't running, so start it via engine.start(_:) instead of recreating or skipping it. Applies under --no-recreate too, since that flag only blocks recreation, not starting. - Only emit .containerRunning after the container is confirmed running (already running for .keep, or successfully started for .start). - Add reconcileDecision tests covering the state dimension: stopped/ exited/created/dead + matching hash -> .start, running + matching hash -> .keep, --no-recreate + stopped -> .start, and stopped + diverged hash -> .removeAndRecreate (not .start).
us
force-pushed
the
fix/compose-up-idempotent
branch
from
July 4, 2026 11:08
ba832ba to
1a43abf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this solve?
mocker compose up -dis not idempotent: re-running on an already-running project errorsConflict … already in use, breaking the standard "edit compose →up -d" workflow. The fix matches Docker's parity contract —up -dis a no-op for unchanged services,--force-recreaterecreates everything,--no-recreatenever recreates — and addresses the same parsed-but-dead-flag anti-pattern the maintainer fixed in PR #27 forimage ls --filter/--format/--no-trunc.Closes #59.
What changed
The config-hash function enumerates its fields explicitly via a private
HashCodingKeysenum, so the hash surface is reviewable in one place and a new field onComposeServicedoes not affect the hash until it is added to the enumeration — matching the safe-by-default contract Docker's normalization provides.The reconcile decision lives in a pure static
reconcileDecision(...)onComposeOrchestrator: no live engine, no fake runtime; the decision matrix is the contract and lives next to the implementation. The orchestrator'sup(...)body becomes a thin coordinator around the helper.--force-recreateand--no-recreateare mutually exclusive at parse time via a custommutating func validate()on each command. Stubs considered and rejected —FlagExclusivity.exclusiveonly applies toEnumerableFlagflags, notBoolflags, so the custom validate path is the Swift-idiomatic equivalent.